//draw a rect with texture.
//require Primitive is TriangleStrip 
//do not need to set vertex buffer

#version 460
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_GOOGLE_include_directive : enable

#include "TextWidgetChar.h"
#include "../CppMacros.h"

layout (push_constant) uniform SStaticTextPushConstant
{
   vec4 TintColor;
   float ZOrder;
} PushConstants;

layout (set=0,binding = 1) uniform STextInfo
{
   StaticCharInfo CharInfos[CHAR_BATCH_SIZE];
} TextInfo;

layout (location = 0) out vec2 outUV;
layout (location = 1) out vec4 outTintColor;

void main() 
{
   /*
      V0                   V1
      ---------------------
      |                   |
      |                   |
      |                   |
      |                   |
      |                   |
      ---------------------
      V2                   V3
   */
   vec2 UVs[4];

   UVs[0]=TextInfo.CharInfos[gl_InstanceIndex].LeftTopUV;
   UVs[1]=vec2(TextInfo.CharInfos[gl_InstanceIndex].RightBottomUV.x,TextInfo.CharInfos[gl_InstanceIndex].LeftTopUV.y);
   UVs[2]=vec2(TextInfo.CharInfos[gl_InstanceIndex].LeftTopUV.x,TextInfo.CharInfos[gl_InstanceIndex].RightBottomUV.y);
   UVs[3]=TextInfo.CharInfos[gl_InstanceIndex].RightBottomUV;

   outUV = UVs[gl_VertexIndex];
   outTintColor=PushConstants.TintColor;

   vec2 Position[4];
   Position[0]=vec2(TextInfo.CharInfos[gl_InstanceIndex].LeftTopPos.x,TextInfo.CharInfos[gl_InstanceIndex].LeftTopPos.y);
   Position[1]=vec2(TextInfo.CharInfos[gl_InstanceIndex].RightBottomPos.x,TextInfo.CharInfos[gl_InstanceIndex].LeftTopPos.y);
   Position[2]=vec2(TextInfo.CharInfos[gl_InstanceIndex].LeftTopPos.x,TextInfo.CharInfos[gl_InstanceIndex].RightBottomPos.y);
   Position[3]=vec2(TextInfo.CharInfos[gl_InstanceIndex].RightBottomPos.x,TextInfo.CharInfos[gl_InstanceIndex].RightBottomPos.y);
   
   gl_Position = vec4(Position[gl_VertexIndex],PushConstants.ZOrder,1);

}